package com.rfid.assistant.activity.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.rfid.assistant.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class FunctionHomeAdapter extends BaseAdapter<FunctionHomeAdapter.MyHolder> {

    private List<String> mData;
    public FunctionHomeAdapter(List<String> items) {
        mData = items;
    }
    @NonNull
    @Override
    public FunctionHomeAdapter.MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MyHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_function_home_layout,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull FunctionHomeAdapter.MyHolder holder, int position) {
        holder.title.setText(mData.get(position));
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mOnItemClickListener != null) {
                    mOnItemClickListener.onClick(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    static class MyHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.title)
        TextView title;
        public MyHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
